/*
 * Title:        CloudScheduler Toolkit
 * Description:  a Toolkit for Modeling and Simulation of Job Scheduling and Resource Provisioning in Cloud System
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 * Author:       Fuhui Wu
 *
 * Copyright (c) 2013-2014, The National University of Defense Technology, China
 */

package org.nudt.jCloud.example.resourceStealing2;

import java.util.ArrayList;
import java.util.List;

import org.nudt.jCloud.infrastructure.Slot;
import org.nudt.jCloud.infrastructure.SlotType;
import org.nudt.jCloud.resourceScaler.ResourceScaler;
import org.nudt.jCloud.simulation.Request;
import org.nudt.jCloud.simulation.RequestData;
import org.nudt.jCloud.simulation.ScaleData;

public class StealingScaler extends ResourceScaler{
	private SlotType slotType;
	private List<Slot> stolenSlotList;
	private List<Slot> usedSlotList;
	
	public StealingScaler(SlotType slotType){
		super();
		setSlotType(slotType);
		stolenSlotList = new ArrayList<Slot>();
		usedSlotList = new ArrayList<Slot>();
	}

	@Override
	public void specialReset() {
		stolenSlotList.clear();
		usedSlotList.clear();
	}

	@Override
	public void scaleResource(RequestData requestData, ScaleData scaleData) {
		int requestSize = 0;
		for(Request request : requestData.getRequestList()){
			requestSize += request.getUnAssignedTasks().size();
		}
		if(requestSize>0){
			scaleData.getToLeaseSlot().put(slotType, requestSize);
		}
	}
	
	public SlotType getSlotType() {
		return slotType;
	}

	public void setSlotType(SlotType slotType) {
		this.slotType = slotType;
	}

	public List<Slot> getUsedSlotList() {
		return usedSlotList;
	}

	public void setUsedSlotList(List<Slot> usedSlotList) {
		this.usedSlotList = usedSlotList;
	}

	public List<Slot> getStolenSlotList() {
		return stolenSlotList;
	}

	public void setStolenSlotList(List<Slot> stolenSlotList) {
		this.stolenSlotList = stolenSlotList;
	}

}
